package com.caogen.cg_wl_kt.base

import android.content.Context
import android.content.Intent
import android.os.Bundle
import android.text.TextUtils
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.Toast
import androidx.activity.result.ActivityResultLauncher
import androidx.annotation.StringRes
import androidx.fragment.app.Fragment
import androidx.lifecycle.ViewModelProvider
import androidx.viewbinding.ViewBinding
import com.caogen.cg_wl_kt.utils.ToastUtils

/**
 * 项目名称: cg_wl_kt
 * Packages:com.caogen.cg_wl_kt.base
 * author: FSW
 * 创建日期: 2024/2/27 19:37
 * Describe:
 *
 */
abstract class BFragment < VB : ViewBinding,VM : BaseViewModel>: Fragment() {
    public lateinit var binding: VB
    public lateinit var vm: VM
    override fun onCreateView(
        inflater: LayoutInflater,
        container: ViewGroup?,
        savedInstanceState: Bundle?
    ): View {
//        binding = inflater(inflater, container)
        binding = binding(inflater, container)
//        binding.lifecycleOwner = this
        vm = ViewModelProvider(this).get(vmClass())
        val view = binding.root as ViewGroup
        return view
    }

    override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
        super.onViewCreated(view, savedInstanceState)
        initView(view)
        setListener()
    }
    open fun initView(view: View?) {

    }

    open fun setListener(){

    }
    override fun onDestroy() {
        super.onDestroy()
    }
    override fun onDestroyView() {
        super.onDestroyView()
    }
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)

    }

    override fun onResume() {
        super.onResume()

    }

    protected abstract fun binding(inflater: LayoutInflater, container: ViewGroup?): VB

    protected open fun vmClass(): Class<VM> {
        return BaseViewModel::class.java as Class<VM>
    }
}